package com.java01.misc.eventdriven;

/**
 * 5 Event-driven example 
 * Demonstrates how to  use CustomEvent, CustomListener, and CustomEventFirer.
 */
public class EventDrivenExample1 implements CustomEventListener{

	private int instanceId;
	
	public EventDrivenExample1(int id){
		this.instanceId=id;
	}
	
	public void customEventOccurs(CustomEvent event) {
		System.out.println("listener "+instanceId+" received event '"+event.getEventName()+"'");
	}
	
	public static void main(String[] args) {
		CustomEventFirer firer = new CustomEventFirer();
		EventDrivenExample1 listener1 = new EventDrivenExample1(1);
		EventDrivenExample1 listener2 = new EventDrivenExample1(2);
		
		firer.addCustomEventListener(listener1);
		firer.addCustomEventListener(listener2);
		
		firer.fireCustomEvent(new CustomEvent(firer,"hello"));
		firer.fireCustomEvent(new CustomEvent(firer,"hi"));
	}
}
